package com.ledim.adapter;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.facebook.drawee.view.SimpleDraweeView;
import com.ledim.adapter.base.LetvBasePagerAdapter;
import com.ledim.bean.ChatRoomBean;
import com.ledim.bean.LedimChoiceCardBean;
import com.ledim.utils.FrescoUtil;
import com.ledim.utils.LedimFunctionUtils;
import com.letv.android.young.client.R;
import java.util.ArrayList;

public class CardA1PageAdapter extends LetvBasePagerAdapter {

    public ArrayList<LedimChoiceCardBean> pList;
    private LayoutInflater mInflater;
    private Context mContext;

    private String groupId;

    public CardA1PageAdapter(Context context, ArrayList<LedimChoiceCardBean> pList,
                             String groupId) {
        super(context, pList);
        mContext = context;
        mInflater = LayoutInflater.from(context);
        this.pList = pList;
        this.groupId = groupId;
    }

    public void setDatas(ArrayList<LedimChoiceCardBean> pList) {
        this.pList = pList;
        notifyDataSetChanged();
    }

    @Override
    protected View fetchView(Object o) {
        View convertView = mInflater.inflate(R.layout.card_a1_item, null);
        SimpleDraweeView mPhoto =
                (SimpleDraweeView) convertView.findViewById(R.id.card_a1_item_photo);
        TextView mTitle = (TextView) convertView.findViewById(R.id.card_a1_item_title);
        SimpleDraweeView mAvatar =
                (SimpleDraweeView) convertView.findViewById(R.id.room_owner_photo_big);
        TextView tv_coin_counts = (TextView) convertView.findViewById(R.id.tv_coin_counts);
        TextView room_creater_name = (TextView) convertView.findViewById(R.id.room_creater_name);
        final LedimChoiceCardBean card = (LedimChoiceCardBean) o;
        final ChatRoomBean room = card.room;
        if (room != null) {
            if (room.cover != null && !TextUtils.isEmpty(room.cover.thumb)) {
                FrescoUtil.loadUrl(room.cover.thumb, mPhoto);
            }
            if (room.status == 1) {
                if (room.current != null && room.current.length() > 0 &&
                        !room.current.equals("null")) {
                    mTitle.setText(room.current.trim());

                } else {
                    mTitle.setText("洗脑循环中");
                }
            } else {
                mTitle.setText("放映结束");
            }
            if (room.user != null) {
                if (!TextUtils.isEmpty(room.user.coin)) {
                    tv_coin_counts.setText(room.user.coin);
                }
                room_creater_name.setText(room.user.nickname);
            }
            if (room.user != null && room.user.avatar != null &&
                    !TextUtils.isEmpty(room.user.avatar.thumb)) {
                FrescoUtil.loadUrl(room.user.avatar.thumb, mAvatar);
            }
        }
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LedimFunctionUtils.jumpTargetActivity((Activity) mContext, card, groupId);
            }
        });
        return convertView;
    }

}
